package com.cgc999.host.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.cgc999.host.R;
import com.cgc999.host.activity.PromoteHomeActivity;
import com.cgc999.host.vo.ContentInfoVo;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import org.xutils.x;

import java.util.List;

public class PromoteArticleListAdapter extends XRecyclerView.Adapter<PromoteArticleListAdapter.Holder> {
    private List<ContentInfoVo> list;

    private Context context;

    public PromoteArticleListAdapter(Context context, List<ContentInfoVo> list) {
        this.list = list;
        this.context = context;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_promote_content_list, parent, false);
        Holder holder = new Holder(view);
        holder.textView = view.findViewById(R.id.txt_promote_home_item);
        holder.imageView = view.findViewById(R.id.img_promote_home_item);
        holder.txtdesc=view.findViewById(R.id.txt_promote_home_item_desc);
        holder.txtName=view.findViewById(R.id.txt_promote_name);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.textView.setText(list.get(position).getTitle());
        x.image().bind(holder.imageView, list.get(position).getCover_url());
        holder.txtdesc.setText(list.get(position).getContent());
        holder.txtName.setText("公众号:"+list.get(position).getPromote_name());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PromoteHomeActivity.class);
//                intent.putExtra("url", "https://www.baidu.com");
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    static class Holder extends RecyclerView.ViewHolder {
        private TextView textView,txtdesc,txtName;
        private ImageView imageView;


        //        private View line;
        public Holder(View itemView) {
            super(itemView);
            textView =itemView.findViewById(R.id.txt_promote_home_item);
            imageView = itemView.findViewById(R.id.img_promote_home_item);
            txtdesc=itemView.findViewById(R.id.txt_promote_home_item_desc);
            txtName=itemView.findViewById(R.id.txt_promote_name);
//            line = itemView.findViewById(R.id.found_item_line);
        }
    }
}
